package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.StoreParam;
import com.tarena.lbs.business.pojo.param.UserLocationParam;
import com.tarena.lbs.business.pojo.query.AreaStoreQuery;
import com.tarena.lbs.business.pojo.query.StoreQuery;
import com.tarena.lbs.business.pojo.vo.StoreVO;
import com.tarena.lbs.business.servcie.StoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;




@Tag(name = "店铺相关功能接口")
@RestController
public class StoreController {


    private static final Logger log = LoggerFactory.getLogger(StoreController.class);
    @Autowired
    private StoreService storeService;


    @Operation(summary = "查询店铺列表")
    @PostMapping("/admin/basic/store/getAll")
    public Result<PageResult<StoreVO>> pageList(@RequestBody StoreQuery query)
            throws BusinessException {
        log.info("查询店铺信息：{}", query);
        Result<PageResult<StoreVO>>  storeList =  storeService.getAllstore(query);
        return  storeList;
    }

    /**
     * 新增店铺
     *
     * @param param
     * @return
     * @throws BusinessException
     */
    @Operation(summary = "新增店铺")
    @PostMapping("/admin/basic/store/add")
    public Result<Void> save(@RequestBody StoreParam param) throws BusinessException {
        return storeService.insertStore(param);
    }


    //查询 属于当前登录用户 所属商家 和满足区域条件的店铺列表
    @Operation(summary = "查询区域下的店铺列表")
    @PostMapping("/admin/basic/store/getStoreByCity")
    public Result<PageResult<StoreVO>> getStoreByCity(@RequestBody AreaStoreQuery query){
        Result<PageResult<StoreVO>>  storeList1 =  storeService.getStoreByCity(query);
        return storeList1;
    }

    @Operation(summary ="删除店铺")
    @DeleteMapping("/admin/basic/store/delete/{id}")
    //根据店铺id删除店铺
    //根据店铺id删除店铺
    public Result<Void> deleteStore(@PathVariable("id") Long id) throws BusinessException {
        return storeService.deleteStore(id);
    }

    @Operation(summary = "准备编辑已有店铺")
    @GetMapping("/admin/basic/store/{id}")
    public Result<StoreVO> selectStore(@PathVariable("id") Long id){
        Result<StoreVO> storeVO = storeService.selectStore(id);
        return storeVO;
    }

    @Operation(summary = "编辑店铺")
    @PutMapping("/admin/basic/store/update")
    public Result<Void> updateStore(@RequestBody StoreParam param) throws BusinessException {
        return storeService.updateStore(param);
    }
    @Operation(summary = "启用店铺")
    @PutMapping("/admin/basic/store/enable/{id}")
    public Result<Void> enableStore(@PathVariable("id") Long id) throws BusinessException {
        return storeService.enableStore(id);
    }
    @Operation(summary = "禁用店铺")
    @PutMapping("/admin/basic/store/disable/{id}")
    public Result<Void> disableStore(@PathVariable("id") Long id) throws BusinessException {
        return storeService.enableStore(id);
    }

    //手机小程序定位上报
    @Operation(summary = "手机小程序定位上报")
    @PostMapping("/basic/store/location")
    public Result<Void> location(@RequestBody UserLocationParam param)
            throws BusinessException{
        return Result.success();
    }

}
